package bpm.dao.impl.user;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.user.Department;

public class DepartmentHierarchyMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int i) throws SQLException {
		Department dept = new Department();
		dept.setId(rs.getInt(1));
		dept.setCode(rs.getString(2));
		dept.setName(rs.getString(3));
		dept.setRank(rs.getInt(4));
		
		Integer pid = rs.getInt(5);
		if(pid != null && pid != 0) {
			dept.setParent(new Department(pid));
			dept.getParent().setCode(rs.getString(6));
			dept.getParent().setName(rs.getString(7));
			dept.getParent().setRank(rs.getInt(8));
		}
		return dept;
	}

}
